<?php
loadLib('view');
class Action extends view{

	static function init()
	{
		return new Action();
	}

	function setup_one()
	{
		if(!IS_POST)
		{
			$this->assign('remote_url',RURI);
			$this->display('index.html');
		}else{
			$domain=isset($_POST['domain']) && !empty($_POST['domain'])?trim($_POST['domain']):'';
			$vertype=isset($_POST['vertype']) && !empty($_POST['vertype'])?trim($_POST['vertype']):'free';
			$key=isset($_POST['key']) && !empty($_POST['key'])?trim($_POST['key']):'';
			$selversion=isset($_POST['selversion']) && !empty($_POST['selversion'])?trim($_POST['selversion']):'';
			if($vertype!='free')
			{
				if(empty($domain) || empty($key))
				{
					$this->_showFail("非免费版，域名与key不能为空");
				}
			}
			if(empty($selversion))
			{
				$this->_showFail('系统版本必选!');
			}
			$url=RURI.'/rapi/?act=installSystem&domain='.$domain."&key={$key}"."&vertype={$vertype}"."&version={$selversion}";
			// echo $url;exit;
			try{
				downURI($url);
			}catch(Exception $ex)
			{
				$this->_showFail('请联系我们!');
			}
				
			$this->_showSuccess();
		}
		
	}

	function _showFail($msg)
	{
		echo "<script>window.parent.window.alert('{$msg}');</script>";
		exit;
	}

	function _showSuccess()
	{
		echo "<script>window.parent.window.installSuccess();</script>";
		exit;
	}

	function setup_two()
	{

	}
}
?>